import java.util.ArrayList;
import java.util.Collection;


public class TaskUtil {

	public Task findStartNode( Collection<Task> tasks ) {
		for(Task task : tasks) {
			if(task.getPredecessors().size() == 0) {
				return task;
			}
		}
		
		return null;
	}
	
	public Task findEndNode( ArrayList<Task> tasks ) {
		for(Task task : tasks) {
			if(task.getSuccessors().size() == 0) {
				return task;
			}
		}
		
		return null;
	}
	
	public Task findTaskById( String taskId, Collection<Task> tasks ) {
		for(Task task: tasks) {
			if(task.getTaskId().equals(taskId)) {
				return task;
			}
		}
		return null;
	}

	public void showErrorAndExit( String msg ) {
		System.out.println(msg);
		System.exit(0);
	}
	
	public void printCriticalPath( Task task ) {
		System.out.println(task.toString());
		
		for(Task succeeding : task.getSuccessors()) {
			if(succeeding.getIsCritical()) {
				printCriticalPath(succeeding);
			}
		}
	}
}
